package com.yzd.learnjava.generics;

import com.yzd.learnjava.util.Print;

public class GenericCast {
	public static int SIZE = 10;
	
	public static void main(String[] args) {
		FixedSizeStack<String> strings = new FixedSizeStack(SIZE);
		
		for(String s : "A B C D E F G H I J".split(" ")) {
			strings.push(s);
		}
		
		for(int i = 0 ; i < SIZE ; i++) {
			String s = strings.pop();
			Print.print(s);
		}
	}
}

class FixedSizeStack<T>{
	private int index = 0;
	private Object[] storages ;
	public FixedSizeStack(int size) {
		storages = new Object[size];
	}
	
	public void push(T item) {
		storages[index++] = item;
	}
	
	public T pop() {
		return (T)storages[--index];
	}
}
